<template>
  <div>
    <van-nav-bar title="商品详情">
      <template #left>
        <van-icon name="arrow-left" @click="goHome" />
      </template>
    </van-nav-bar>

    <van-image style="width: 96%" height="300" :src="$host + this.x.img" />
    <p>{{ this.x.goodsname }}</p>
    <van-button type="danger" @click="add">加入购物车</van-button>
  </div>
</template>
<script>
export default {
  created() {
    this.$http
      .get("/getgoodsinfo", { params: { id: this.$route.params.id } })
      .then((res) => {
        this.x = res.data.list[0];
        console.log(res);
        this.goodsid = res.data.list[0].id;
      });
  },
  data() {
    return {
      x: [],
      uid: JSON.parse(localStorage.userInfo).uid,
      goodsid:this.goodsid,
      num: 1,
    };
  },
  methods: {
    goHome() {
      this.$router.go(-1);
    },

    add() {
      this.$http
        .post("/cartadd", {
          uid: this.uid,
          goodsid: this.goodsid,
          num: this.num,
        })
        .then((res) => {
          console.log(res);
        });
    },
  },
};
</script>